<template>
	<div>

		<el-row :gutter="10">
			<a href="/doctor_information">
				<el-button type="infor">医生信息</el-button>
			</a>
		</el-row>
		<br />

		<el-row :gutter="10">
			<el-col :span="19">
				<el-button type="primary" icon="el-icon-circle-plus-outline" plain @click="add()">添加</el-button>
			</el-col>
		</el-row>
		<el-table :data="result.tableData" style="width: 100%" @selection-change="handleSelectionChange">
			<el-table-column label="序号" prop="id" align="center">

			</el-table-column>

			<el-table-column label="姓名" prop="name" align="center">
			</el-table-column>

			<el-table-column label="性别" prop="gender" align="center">
			</el-table-column>

			<el-table-column label="年龄" prop="age" align="center">
			</el-table-column>

			<el-table-column label="类别" prop="type" align="center">
				<template slot-scope="scope">
				
					<el-tag v-if="scope.row.type == '家属'">家属</el-tag>
				
					<el-tag v-if="scope.row.type == '紧急联系人'">紧急联系人</el-tag>
					
					<el-tag v-if="scope.row.type == '陪住人'">陪住人</el-tag>
				</template>
			</el-table-column>

			<el-table-column label="与老人关系" prop="relationship" align="center">
			</el-table-column>

			<el-table-column label="身份证号" prop="idNum" align="center">
			</el-table-column>

			<el-table-column label="住址" prop="address" align="center">
			</el-table-column>

			<el-table-column label="电话" prop="telephone" align="center">
			</el-table-column>

			<el-table-column label="操作" align="center">
				<template slot-scope="scope">
					<el-button size="mini" @click="edit(scope.row.id)">编辑</el-button><br/>
					<el-button size="mini" type="danger" @click="del(scope.row.id)">删除</el-button>
				</template>
			</el-table-column>

		</el-table>
		<el-dialog :title="title" :visible.sync="show" :close-on-click-modal="false" width="500px">
			<PersonnelInformationEdit v-if="show" :show.sync="show" @getData="getData()" :editid="editid" :key="showNum">
			</PersonnelInformationEdit>
		</el-dialog>


		<el-pagination style="margin-top:20px;" background layout="prev, pager, next" :page-count="result.pages"
			:current-page.sync="query.pageNo" :page-size="query.pageSize" @current-change="getData()">
		</el-pagination>


	</div>
</template>

<script>
	import PersonnelInformationEdit from '@/views/personnel_information/edit'
	export default {
		name: 'PersonnelInformation',
		components: {
			PersonnelInformationEdit,
		},
		data() {
			return {
				showNum: 0,
				editid: null,
				search: {
					name: ''
				},
				query: {
					name: '',
					pageNo: 1,
					pageSize: 8
				},
				result: {
					tableData: [],
					pages: 0
				},
				show: false,
				selectedrow: [],
				title: ''
			}
		},
		created() {
			this.getData()
		},
		methods: {
			getData() {
				this.axios.get('/personnelInformation/list', response => {
					this.result.tableData = response.obj.records
					this.result.pages = response.obj.pages
					console.log(this.result.tableData)
				}, this.query)
			},
			edit(id) {
				this.title = '修改';
				this.editid = id;
				this.showNum++;
				this.show = true;
			},
			add() {
				this.title = '添加';
				this.showNum++;
				this.editid = null;
				this.show = true;
			},

			del(id) {
				this.axios.del('/personnelInformation/del', response => {
					this.getData()
				}, {
					id: id
				})
			},
			handleSelectionChange(val) {
				// val参数为所有选中行的数据
				this.selectedrow = val
			},
			batchdel() {
				if (this.selectedrow.length === 0) {
					this.$message('没有任何被选中的数据');
				} else {
					const ids = []
					for (let i = 0; i < this.selectedrow.length; i++) {
						ids.push(this.selectedrow[i].id)
					}
					this.axios.del('/ums-user/batchdel', response => {
						this.getData()
					}, {
						ids: ids
					})
				}
			},
			handleBack(id) {
				this.axios.del('/ums-user/back', response => {
					this.getData()
				}, {
					id: id
				}, 'back')
			},
			gorole(id) {
				this.$router.push({
					path: '/user-role',
					query: {
						id: id
					}
				})
			}
		}
	}
</script>
<style scoped>
	/* el-table el-table-column{
		text-align: center;
	} */
</style>
